﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>HTML ConTrol</title>
    <script language="javascript">
        var a = new Array();
        var n=new Number();
        var S= new Number();
        var Chuoi= new String();
       function XuLy()
       {
        Chuoi=document.getElementById("txt_mang").value;
        a=Chuoi.split(",");
//        a[0]=1;
//        a[1]=2;
//        a[2]=3;
//        a[3]=4;
        //n=4;
        n=a.length;
       for(var i=0;i<n;i++)
        {
            a[i]=parseInt(a[i]);
        }
        S=0;
        for(var i=0;i<n;i++)
        {
            if(a[i]>0)
            {
                S+=a[i];
            }
        } 
        var newChild;
       var oldChild;
       
       Chuoi="Tổng là: "+S;
       newChild=document.createTextNode(Chuoi);
       oldChild=document.getElementById("kq").childNodes[0];
       
       document.getElementById("kq").replaceChild(newChild,oldChild);
        }
    </script>
</head>
<body>
<h1>sTổng các phần tử dương trong mảng</h1>
 Nhập dãy số: 
 <input id="txt_mang" type="text" />
<input type="button" id="btn" value="Kết quả" onclick="XuLy()" />
<div id="kq">&nbsp</div>
</body>
</html>
